using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using HappySprite;
using HappySprite.Graphics;

namespace HappyInvaders
{
    class ShelterVisual : Visual
    {
        Texture2D texture;

        public ShelterVisual()
        {
            Item.RenderItem.Width = Constants.ShelterWidth;
            Item.RenderItem.Height = Constants.ShelterHeight;
        }

        public override void SetTexture(BitArray bitArray)
        {
            if (texture != null)
                texture.Dispose();

            texture = new Texture2D(Global.Renderer.Graphics.GraphicsDevice, 32, 32, 0, TextureUsage.AutoGenerateMipMap, SurfaceFormat.Color);

            uint[] bitmap = new uint[32 * 32];
            texture.GetData(bitmap);

            for (int i = 0; i < 24; i++)
            {
                for (int j = 0; j < 16; j++)
                {
                    if (bitArray[i + j * 24])
                        bitmap[i + j * 32] = 0xFF00FF00; // Green
                }
            }

            texture.SetData(bitmap);

            Item.RenderItem.ImageMap = new ImageMap(texture, Vector2.Zero, new Vector2(24f / 32f, 16f / 32f));
        }
    }
}
